﻿using System;
//using System;
//using System.Collections.Generic;
//using System.Windows.Forms;
using System.IO;
using System.Text;
using System.Windows.Forms;
//using System.Text;
//using System.ComponentModel;
//using System.Drawing;
namespace Module_Debug
{
    public partial class OTP_CODE_GEN : Form
    {
        //frmMain MainForm = null;
        public OTP_CODE_GEN(frmMain Frm)
        {
            //MainForm = Frm;
            InitializeComponent();
        }

        private void OTP_1st_CheckedChanged(object sender, EventArgs e)
        {

            //Main_txtbox.Text += "//" +A1.Text + ","+B1.Text + "," + C1.Text + "," + D1.Text + "," + E1.Text + ","  + F1.Text + "," + G1.Text +
            //    "," + H1.Text + "," + I1.Text + "," + J1.Text + "1st OTP"+"\r\n";
            //所有的注释放在开头

            //有瑕疵
            //勾选上，增加一行
            //勾选取消，删除所增加的行  找"\r\n"
            //

        }
        private void OTP_2nd_CheckedChanged(object sender, EventArgs e)
        {
            //Main_txtbox.Text += "//" + A1.Text + "," + B1.Text + "," + C1.Text + "," + D1.Text + "," + E1.Text + "," + F1.Text + "," + G1.Text +
            //    "," + H1.Text + "," + I1.Text + "," + J1.Text + "2nd OTP" + "\r\n";
            ////所有的注释放在开头
        }
        private void OTP_3rd_CheckedChanged(object sender, EventArgs e)
        {
            //Main_txtbox.Text += "//" + A1.Text + "," + B1.Text + "," + C1.Text + "," + D1.Text + "," + E1.Text + "," + F1.Text + "," + G1.Text +
            //    "," + H1.Text + "," + I1.Text + "," + J1.Text + "3rd OTP" + "\r\n";
            ////所有的注释放在开头
        }


        //中间部分代码处理函数
        private void Mid_txt()
        {


            //Main_txtbox.Text += "FE" + ","+ AP1.Text + "\r\n";//强切
            ////ToInt32(A, 2);//二进制的A转换为10进制。(A, 2)表示2进制A
            //string A_H_bin = AD7.Text + AD6.Text + AD5.Text + AD4.Text;//二进制字符串  高四位
            //string A_L_bin = AD3.Text + AD2.Text + AD1.Text + AD0.Text;//二进制字符串  低四位
            //Main_txtbox.Text += AR1.Text + ',' + System.Convert.ToString(Convert.ToInt32(A_H_bin, 2), 16).ToUpper();
            //Main_txtbox.Text += System.Convert.ToString(Convert.ToInt32(A_L_bin, 2), 16).ToUpper() + "//" + A1.Text + "\r\n";
            //AHEX.Text = System.Convert.ToString(Convert.ToInt32(A_H_bin, 2), 16).ToUpper()+System.Convert.ToString(Convert.ToInt32(A_L_bin, 2), 16).ToUpper();//写16进制那列



            //Main_txtbox.Text += "FE" + "," + AP1.Text + "\r\n";//强切
            //Main_txtbox.Text += AR1.Text + ',' + AHEX.Text+ "//" + A1.Text + "\r\n";

            //Main_txtbox.Text += "FE" + "," + BP1.Text + "\r\n";//强切
            //Main_txtbox.Text += BR1.Text + ','+BHEX.Text+ "//" + B1.Text + "\r\n";

            //Main_txtbox.Text += "FE" + "," + CP1.Text + "\r\n";//强切
            //Main_txtbox.Text += CR1.Text + ',' + CHEX.Text + "//" + C1.Text + "\r\n";

            //Main_txtbox.Text += "FE" + "," + DP1.Text + "\r\n";//强切 
            //Main_txtbox.Text += DR1.Text + ',' + DHEX.Text + "//" + D1.Text + "\r\n";

            //Main_txtbox.Text += "FE" + "," + EP1.Text + "\r\n";//强切                
            //Main_txtbox.Text += ER1.Text + ',' +EHEX.Text + "//" + E1.Text + "\r\n";

            //Main_txtbox.Text += "FE" + "," + FP1.Text + "\r\n";//强切               
            //Main_txtbox.Text += FR1.Text + ',' + FHEX.Text + "//" + F1.Text + "\r\n";

            //Main_txtbox.Text += "FE" + "," + GP1.Text + "\r\n";//强切
            //Main_txtbox.Text += GR1.Text + ','+ GHEX.Text+ "//" + G1.Text + "\r\n";

            //Main_txtbox.Text += "FE" + "," + HP1.Text + "\r\n";//强切 
            //Main_txtbox.Text += HR1.Text + ',' + HHEX.Text + "//" + H1.Text + "\r\n";

            //Main_txtbox.Text += "FE" + "," + IP1.Text + "\r\n";//强切
            //Main_txtbox.Text += IR1.Text + ',' + IHEX.Text + "//" + I1.Text + "\r\n";

            //Main_txtbox.Text += "FE" + "," + JP1.Text + "\r\n";//强切
            //Main_txtbox.Text += JR1.Text + ','+JHEX.Text + "//" + J1.Text + "\r\n";

        }

        ////生成代码
        //private void GEN_Click(object sender, EventArgs e)
        //{

        //    Main_txtbox.Text +="FE,00" + "\r\n" + "28" + "\r\n" + "10" + "\r\n"; //烧录头代码
        //    Mid_txt();// 烧录中间代码
        //    Main_txtbox.Text +="FE,40" + "\r\n" + "F2,01" + "\r\n" + "F3,A5" + "\r\n" + "F4,5A"  +"\r\n" + "F5,3C" +"\r\n";// 烧录尾代码
        //    Post_process();
        //}

        //private void flag_Click(object sender, EventArgs e)
        //{
        //    Mid_txt();// 中间代码
        //    Post_process();
        //}


        //生成main.txt后处理
        //private void Post_process()
        //{

        //    //Replace(String oldValue, String newValue);
        //    Main_txtbox.Text = Main_txtbox.Text.Replace("//\r\n", "\r\n");//   删除//后面只有一个换行符的//
        //    Main_txtbox.Text = Main_txtbox.Text.Replace("FE,\r\n,00\r\n", "");  //删除占两行的字符串
        //    Main_txtbox.Text = Main_txtbox.Text.Replace(",00\r\n", "");//删除,00\r\n
        //    Main_txtbox.Text = Main_txtbox.Text.Replace("FE\r\n", "");//删除FE\r\n
        //    Main_txtbox.Text = Main_txtbox.Text.Replace("FE,\r\n,\r\n", "");
        //    //特殊处理首行出现的FE,00/r/n 的,00/r/n被删除结果变为FE28/r/n，为使FE28/r/n变为FE,00/r/n28/r/n再针对首行做特殊处理

        //    Main_txtbox.Text = Main_txtbox.Text.Replace("FE28\r\n", "FE,00\r\n28\r\n");

        //    //不合并也可以
        //    //乾坤大挪移          合并同寄存器  和尾代码在同一配置页的合并 FE,40
        //    //怎么写？

        //}

        ////清空文本框
        //private void clear_Click(object sender, EventArgs e)
        //{
        //    Main_txtbox.Text = "";
        //}


        //置fause按键
        //private void Set_false_Click(object sender, EventArgs e)
        //{
        //    chk_A7.Checked = chk_A6.Checked = chk_A5.Checked = chk_A4.Checked = chk_A3.Checked = chk_A2.Checked = chk_A1.Checked = chk_A0.Checked = false;
        //    //chk_B7.Checked = chk_B6.Checked = chk_B5.Checked = chk_B4.Checked = chk_B3.Checked = chk_B2.Checked = chk_B1.Checked = chk_B0.Checked = false;
        //    //chk_C7.Checked = chk_C6.Checked = chk_C5.Checked = chk_C4.Checked = chk_C3.Checked = chk_C2.Checked = chk_C1.Checked = chk_C0.Checked = false;
        //    //chk_D7.Checked = chk_D6.Checked = chk_D5.Checked = chk_D4.Checked = chk_D3.Checked = chk_D2.Checked = chk_D1.Checked = chk_D0.Checked = false;
        //    //chk_E7.Checked = chk_E6.Checked = chk_E5.Checked = chk_E4.Checked = chk_E3.Checked = chk_E2.Checked = chk_E1.Checked = chk_E0.Checked = false;
        //    //chk_F7.Checked = chk_F6.Checked = chk_F5.Checked = chk_F4.Checked = chk_F3.Checked = chk_F2.Checked = chk_F1.Checked = chk_F0.Checked = false;
        //    //chk_G7.Checked = chk_G6.Checked = chk_G5.Checked = chk_G4.Checked = chk_G3.Checked = chk_G2.Checked = chk_G1.Checked = chk_G0.Checked = false;
        //    //chk_H7.Checked = chk_H6.Checked = chk_H5.Checked = chk_H4.Checked = chk_H3.Checked = chk_H2.Checked = chk_H1.Checked = chk_H0.Checked = false;
        //    //chk_I7.Checked = chk_I6.Checked = chk_I5.Checked = chk_I4.Checked = chk_I3.Checked = chk_I2.Checked = chk_I1.Checked = chk_I0.Checked = false;
        //    //chk_J7.Checked = chk_J6.Checked = chk_J5.Checked = chk_J4.Checked = chk_J3.Checked = chk_J2.Checked = chk_J1.Checked = chk_J0.Checked = false;
        //}

        private void Save_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.InitialDirectory = @"C:\Users\Desktop";
            sfd.Title = "请选择要保存的文件路径";
            sfd.Filter = "文本文件|*.txt|所有文件|*.*";
            sfd.ShowDialog();

            //获得用户要保存的文件的路径
            string path = sfd.FileName;
            if (path == "")
            {
                return;
            }
            using (FileStream fsWrite = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
            {
                //byte[] buffer = Encoding.Default.GetBytes(Main_txtbox.Text);
                byte[] buffer = Encoding.Default.GetBytes(Display_Box.Text);

                fsWrite.Write(buffer, 0, buffer.Length);
            }
            MessageBox.Show("保存成功");
        }

        private void btn_erase_Click(object sender, EventArgs e)
        {
            //Reg Page HEX 列 清空
            //AR1.Text = BR1.Text = CR1.Text = DR1.Text = ER1.Text = FR1.Text = GR1.Text = HR1.Text = IR1.Text = JR1.Text = "";
            //AP1.Text = BP1.Text = CP1.Text = DP1.Text = EP1.Text = FP1.Text = GP1.Text = HP1.Text = IP1.Text = JP1.Text = "";
            //AHEX.Text = BHEX.Text = CHEX.Text = DHEX.Text = EHEX.Text = FHEX.Text = GHEX.Text = HHEX.Text = IHEX.Text = JHEX.Text = "";
            //A1.Text = B1.Text = C1.Text = D1.Text = E1.Text = F1.Text = G1.Text = H1.Text = I1.Text = J1.Text = "";
        }

        #region     // chk_A、chk_J的check事件
        //private void chk_A(object sender, EventArgs e)
        //{
        //    byte temp = 0;
        //    if (chk_A7.Checked)
        //        temp |= 0x80;//最高位置1，其余位不动
        //    else temp &= 0x7F;//最高位置0，其余位不动

        //    if (chk_A6.Checked)
        //        temp |= 0x40;
        //    else temp &= 0xbF;

        //    if (chk_A5.Checked)
        //        temp |= 0x20;
        //    else temp &= 0xDF;

        //    if (chk_A4.Checked)
        //        temp |= 0x10;
        //    else temp &= 0xEF;

        //    if (chk_A3.Checked)
        //        temp |= 0x08;
        //    else temp &= 0xF7;

        //    if (chk_A2.Checked)
        //        temp |= 0x04;
        //    else temp &= 0xFB;

        //    if (chk_A1.Checked)
        //        temp |= 0x02;
        //    else temp &= 0xFD;

        //    if (chk_A0.Checked)
        //        temp |= 0x01;
        //    else temp &= 0xFE;

        //    //ToString(byte value, int toBase);
        //    //PadLeft(int totalWidth, char paddingChar);
        //    AHEX.Text = Convert.ToString(temp, 16).ToUpper().PadLeft(2, '0');



        //}

        //private void chk_B(object sender, EventArgs e)
        //{
        //    byte temp = 0;
        //    if (chk_B7.Checked)
        //        temp |= 0x80;//最高位置1，其余位不动
        //    else temp &= 0x7F;//最高位置0，其余位不动

        //    if (chk_B6.Checked)
        //        temp |= 0x40;
        //    else temp &= 0xbF;

        //    if (chk_B5.Checked)
        //        temp |= 0x20;
        //    else temp &= 0xDF;

        //    if (chk_B4.Checked)
        //        temp |= 0x10;
        //    else temp &= 0xEF;

        //    if (chk_B3.Checked)
        //        temp |= 0x08;
        //    else temp &= 0xF7;

        //    if (chk_B2.Checked)
        //        temp |= 0x04;
        //    else temp &= 0xFB;

        //    if (chk_B1.Checked)
        //        temp |= 0x02;
        //    else temp &= 0xFD;

        //    if (chk_B0.Checked)
        //        temp |= 0x01;
        //    else temp &= 0xFE;

        //    //ToString(byte value, int toBase);
        //    BHEX.Text = Convert.ToString(temp, 16).ToUpper().PadLeft(2, '0');


        //}

        //private void chk_C(object sender, EventArgs e)
        //{
        //    byte temp = 0;
        //    if (chk_C7.Checked)
        //        temp |= 0x80;//最高位置1，其余位不动
        //    else temp &= 0x7F;//最高位置0，其余位不动

        //    if (chk_C6.Checked)
        //        temp |= 0x40;
        //    else temp &= 0xbF;

        //    if (chk_C5.Checked)
        //        temp |= 0x20;
        //    else temp &= 0xDF;

        //    if (chk_C4.Checked)
        //        temp |= 0x10;
        //    else temp &= 0xEF;

        //    if (chk_C3.Checked)
        //        temp |= 0x08;
        //    else temp &= 0xF7;

        //    if (chk_C2.Checked)
        //        temp |= 0x04;
        //    else temp &= 0xFB;

        //    if (chk_C1.Checked)
        //        temp |= 0x02;
        //    else temp &= 0xFD;

        //    if (chk_C0.Checked)
        //        temp |= 0x01;
        //    else temp &= 0xFE;

        //    //ToString(byte value, int toBase);
        //    //CHEX.Text = Convert.ToString(temp, 16).ToUpper().PadLeft(2, '0') ;
        //}

        //private void chk_D(object sender, EventArgs e)
        //{
        //    byte temp = 0;
        //    if (chk_D7.Checked)
        //        temp |= 0x80;//最高位置1，其余位不动
        //    else temp &= 0x7F;//最高位置0，其余位不动

        //    if (chk_D6.Checked)
        //        temp |= 0x40;
        //    else temp &= 0xbF;

        //    if (chk_D5.Checked)
        //        temp |= 0x20;
        //    else temp &= 0xDF;

        //    if (chk_D4.Checked)
        //        temp |= 0x10;
        //    else temp &= 0xEF;

        //    if (chk_D3.Checked)
        //        temp |= 0x08;
        //    else temp &= 0xF7;

        //    if (chk_D2.Checked)
        //        temp |= 0x04;
        //    else temp &= 0xFB;

        //    if (chk_D1.Checked)
        //        temp |= 0x02;
        //    else temp &= 0xFD;

        //    if (chk_D0.Checked)
        //        temp |= 0x01;
        //    else temp &= 0xFE;

        //    //ToString(byte value, int toBase);
        //    DHEX.Text = Convert.ToString(temp, 16).ToUpper().PadLeft(2, '0') ;
        //}

        //private void chk_E(object sender, EventArgs e)
        //{
        //    byte temp = 0;
        //    if (chk_E7.Checked)
        //        temp |= 0x80;//最高位置1，其余位不动
        //    else temp &= 0x7F;//最高位置0，其余位不动

        //    if (chk_E6.Checked)
        //        temp |= 0x40;
        //    else temp &= 0xbF;

        //    if (chk_E5.Checked)
        //        temp |= 0x20;
        //    else temp &= 0xDF;

        //    if (chk_E4.Checked)
        //        temp |= 0x10;
        //    else temp &= 0xEF;

        //    if (chk_E3.Checked)
        //        temp |= 0x08;
        //    else temp &= 0xF7;

        //    if (chk_E2.Checked)
        //        temp |= 0x04;
        //    else temp &= 0xFB;

        //    if (chk_E1.Checked)
        //        temp |= 0x02;
        //    else temp &= 0xFD;

        //    if (chk_E0.Checked)
        //        temp |= 0x01;
        //    else temp &= 0xFE;

        //    //ToString(byte value, int toBase);
        //    EHEX.Text = Convert.ToString(temp, 16).ToUpper().PadLeft(2, '0') ;
        //}

        //private void chk_F(object sender, EventArgs e)
        //{
        //    byte temp = 0;
        //    if (chk_F7.Checked)
        //        temp |= 0x80;//最高位置1，其余位不动
        //    else temp &= 0x7F;//最高位置0，其余位不动

        //    if (chk_F6.Checked)
        //        temp |= 0x40;
        //    else temp &= 0xbF;

        //    if (chk_F5.Checked)
        //        temp |= 0x20;
        //    else temp &= 0xDF;

        //    if (chk_F4.Checked)
        //        temp |= 0x10;
        //    else temp &= 0xEF;

        //    if (chk_F3.Checked)
        //        temp |= 0x08;
        //    else temp &= 0xF7;

        //    if (chk_F2.Checked)
        //        temp |= 0x04;
        //    else temp &= 0xFB;

        //    if (chk_F1.Checked)
        //        temp |= 0x02;
        //    else temp &= 0xFD;

        //    if (chk_F0.Checked)
        //        temp |= 0x01;
        //    else temp &= 0xFE;

        //    //ToString(byte value, int toBase);
        //    FHEX.Text = Convert.ToString(temp, 16).ToUpper().PadLeft(2, '0') ;

        //}

        //private void chk_G(object sender, EventArgs e)
        //{
        //    byte temp = 0;
        //    if (chk_G7.Checked)
        //        temp |= 0x80;//最高位置1，其余位不动
        //    else temp &= 0x7F;//最高位置0，其余位不动

        //    if (chk_G6.Checked)
        //        temp |= 0x40;
        //    else temp &= 0xbF;

        //    if (chk_G5.Checked)
        //        temp |= 0x20;
        //    else temp &= 0xDF;

        //    if (chk_G4.Checked)
        //        temp |= 0x10;
        //    else temp &= 0xEF;

        //    if (chk_G3.Checked)
        //        temp |= 0x08;
        //    else temp &= 0xF7;

        //    if (chk_G2.Checked)
        //        temp |= 0x04;
        //    else temp &= 0xFB;

        //    if (chk_G1.Checked)
        //        temp |= 0x02;
        //    else temp &= 0xFD;

        //    if (chk_G0.Checked)
        //        temp |= 0x01;
        //    else temp &= 0xFE;

        //    //ToString(byte value, int toBase);
        //    GHEX.Text = Convert.ToString(temp, 16).ToUpper().PadLeft(2, '0') ;
        //}

        //private void chk_H(object sender, EventArgs e)
        //{
        //    byte temp = 0;
        //    if (chk_H7.Checked)
        //        temp |= 0x80;//最高位置1，其余位不动
        //    else temp &= 0x7F;//最高位置0，其余位不动

        //    if (chk_H6.Checked)
        //        temp |= 0x40;
        //    else temp &= 0xbF;

        //    if (chk_H5.Checked)
        //        temp |= 0x20;
        //    else temp &= 0xDF;

        //    if (chk_H4.Checked)
        //        temp |= 0x10;
        //    else temp &= 0xEF;

        //    if (chk_H3.Checked)
        //        temp |= 0x08;
        //    else temp &= 0xF7;

        //    if (chk_H2.Checked)
        //        temp |= 0x04;
        //    else temp &= 0xFB;

        //    if (chk_H1.Checked)
        //        temp |= 0x02;
        //    else temp &= 0xFD;

        //    if (chk_H0.Checked)
        //        temp |= 0x01;
        //    else temp &= 0xFE;

        //    //ToString(byte value, int toBase);
        //    HHEX.Text = Convert.ToString(temp, 16).ToUpper().PadLeft(2, '0') ;
        //}

        //private void chk_I(object sender, EventArgs e)
        //{
        //    byte temp = 0;
        //    if (chk_I7.Checked)
        //        temp |= 0x80;//最高位置1，其余位不动
        //    else temp &= 0x7F;//最高位置0，其余位不动

        //    if (chk_I6.Checked)
        //        temp |= 0x40;
        //    else temp &= 0xbF;

        //    if (chk_I5.Checked)
        //        temp |= 0x20;
        //    else temp &= 0xDF;

        //    if (chk_I4.Checked)
        //        temp |= 0x10;
        //    else temp &= 0xEF;

        //    if (chk_I3.Checked)
        //        temp |= 0x08;
        //    else temp &= 0xF7;

        //    if (chk_I2.Checked)
        //        temp |= 0x04;
        //    else temp &= 0xFB;

        //    if (chk_I1.Checked)
        //        temp |= 0x02;
        //    else temp &= 0xFD;

        //    if (chk_I0.Checked)
        //        temp |= 0x01;
        //    else temp &= 0xFE;

        //    //ToString(byte value, int toBase);
        //    IHEX.Text = Convert.ToString(temp, 16).ToUpper().PadLeft(2, '0') ;
        //}

        //private void chk_J(object sender, EventArgs e)
        //{
        //    byte temp = 0;
        //    if (chk_J7.Checked)
        //        temp |= 0x80;//最高位置1，其余位不动
        //    else temp &= 0x7F;//最高位置0，其余位不动

        //    if (chk_J6.Checked)
        //        temp |= 0x40;
        //    else temp &= 0xbF;

        //    if (chk_J5.Checked)
        //        temp |= 0x20;
        //    else temp &= 0xDF;

        //    if (chk_J4.Checked)
        //        temp |= 0x10;
        //    else temp &= 0xEF;

        //    if (chk_J3.Checked)
        //        temp |= 0x08;
        //    else temp &= 0xF7;

        //    if (chk_J2.Checked)
        //        temp |= 0x04;
        //    else temp &= 0xFB;

        //    if (chk_J1.Checked)
        //        temp |= 0x02;
        //    else temp &= 0xFD;

        //    if (chk_J0.Checked)
        //        temp |= 0x01;
        //    else temp &= 0xFE;

        //    //ToString(byte value, int toBase);
        //    JHEX.Text = Convert.ToString(temp, 16).ToUpper().PadLeft(2, '0') ;
        //}

        #endregion


        //private void CheckBox12_CheckedChanged(object sender, EventArgs e)
        //{
        //    //if(checkBox12.Checked)
        //        chkp40d7.Checked = false;
        //   // else
        //        chkp40d7.Checked = true;

        //}


        //private void RdoOtp1_CheckedChanged(object sender, EventArgs e)
        //{
        //    byte otpreg40 = 0;
        //    if (AP1.SelectedIndex == AP1.Items.IndexOf("40")&&(rdoOtp1.Checked))
        //    {
        //        numOtpReg.Value = 0xf6; otpreg40 |= 1<<0;
        //    }
        //    else if (AP1.SelectedIndex == AP1.Items.IndexOf("40") && (rdoOtp2.Checked))
        //    {
        //        numOtpReg.Value = 0xf7; otpreg40 |= 1 << 0;
        //    }

        //    if (AP1.SelectedIndex == AP1.Items.IndexOf("60") && (rdoOtp1.Checked))
        //    {
        //        numOtpReg.Value = 0xf6; otpreg40 |= 1 << 1;
        //    }
        //    else if (AP1.SelectedIndex == AP1.Items.IndexOf("60") && (rdoOtp2.Checked))
        //    {
        //        numOtpReg.Value = 0xf7; otpreg40 |= 1 << 1;
        //    }

        //    if (AP1.SelectedIndex == AP1.Items.IndexOf("70") && (rdoOtp1.Checked))
        //    {
        //        numOtpReg.Value = 0xf6; otpreg40 |= 1 << 2;
        //    }
        //    else if (AP1.SelectedIndex == AP1.Items.IndexOf("70") && (rdoOtp2.Checked))
        //    {
        //        numOtpReg.Value = 0xf7; otpreg40 |= 1 << 2;
        //    }

        //    if (AP1.SelectedIndex == AP1.Items.IndexOf("80") && (rdoOtp1.Checked))
        //    {
        //        numOtpReg.Value = 0xf6; otpreg40 |= 1 << 3;
        //    }
        //    else if (AP1.SelectedIndex == AP1.Items.IndexOf("80") && (rdoOtp2.Checked))
        //    {
        //        numOtpReg.Value = 0xf7; otpreg40 |= 1 << 3;
        //    }

        //    if (AP1.SelectedIndex == AP1.Items.IndexOf("90") && (rdoOtp1.Checked))
        //    {
        //        numOtpReg.Value = 0xf6; otpreg40 |= 1 << 4;
        //    }
        //    else if (AP1.SelectedIndex == AP1.Items.IndexOf("90") && (rdoOtp2.Checked))
        //    {
        //        numOtpReg.Value = 0xf7; otpreg40 |= 1 << 4;
        //    }

        //    if (AP1.SelectedIndex == AP1.Items.IndexOf("E0") && (rdoOtp1.Checked))
        //    {
        //        numOtpReg.Value = 0xf6; otpreg40 |= 1 << 5;
        //    }
        //    else if (AP1.SelectedIndex == AP1.Items.IndexOf("E0") && (rdoOtp2.Checked))
        //    {
        //        numOtpReg.Value = 0xf7; otpreg40 |= 1 << 5;
        //    }

        //    if (AP1.SelectedIndex == AP1.Items.IndexOf("E2") && (rdoOtp1.Checked))
        //    {
        //        numOtpReg.Value = 0xf6; otpreg40 |= 1 << 6;
        //    }
        //    else if (AP1.SelectedIndex == AP1.Items.IndexOf("E2") && (rdoOtp2.Checked))
        //    {
        //        numOtpReg.Value = 0xf7; otpreg40 |= 1 << 6;
        //    }

        //    if (AP1.SelectedIndex == AP1.Items.IndexOf("10") && (rdoOtp1.Checked))
        //    {
        //        numOtpReg.Value = 0xf6; otpreg40 |= 1 << 7;
        //    }
        //    else if (AP1.SelectedIndex == AP1.Items.IndexOf("10") && (rdoOtp2.Checked))
        //    {
        //        numOtpReg.Value = 0xf7; otpreg40 |= 1 << 7;
        //    }
        //    #region //显示当前 program enable reg 标志位
        //    if ((otpreg40 & (1<<0)) >0)
        //    {
        //        chkbit0.Checked = true;
        //    }
        //    else chkbit0.Checked = false;

        //    if ((otpreg40 & (1 << 1)) >0)
        //    {
        //        chkbit1.Checked = true;
        //    }
        //    else chkbit1.Checked = false;
        //    if ((otpreg40 & (1 << 2)) >0)
        //    {
        //        chkbit2.Checked = true;
        //    }
        //    else chkbit2.Checked = false;
        //    if ((otpreg40 & (1 << 3)) > 0)
        //    {
        //        chkbit3.Checked = true;
        //    }
        //    else chkbit3.Checked = false;
        //    if ((otpreg40 & (1 << 4)) > 0)
        //    {
        //        chkbit4.Checked = true;
        //    }
        //    else chkbit4.Checked = false;
        //    if ((otpreg40 & (1 << 5)) > 0)
        //    {
        //        chkbit5.Checked = true;
        //    }
        //    else chkbit5.Checked = false;
        //    if ((otpreg40 & (1 << 6)) > 0)
        //    {
        //        chkbit6.Checked = true;
        //    }
        //    else chkbit6.Checked = false;
        //    if ((otpreg40 & (1 << 7)) > 0)
        //    {
        //        chkbit7.Checked = true;
        //    }
        //    else chkbit7.Checked = false;
        //    #endregion
        //    numahex.Value = otpreg40;


        //    //if (AP1.SelectedIndex == AP1.Items.IndexOf("40")
        //    //     | (AP1.SelectedIndex == AP1.Items.IndexOf("60"))
        //    //     | (AP1.SelectedIndex == AP1.Items.IndexOf("70"))
        //    //     | (AP1.SelectedIndex == AP1.Items.IndexOf("80"))
        //    //     | (AP1.SelectedIndex == AP1.Items.IndexOf("90"))
        //    //     | (AP1.SelectedIndex == AP1.Items.IndexOf("E0"))
        //    //     )
        //    // {
        //    //     if(rdoOtp1.Checked)
        //    //     { numOtpReg.Value = 0xf6; }
        //    //     else if (rdoOtp2.Checked)
        //    //     {
        //    //         numOtpReg.Value = 0xf7;
        //    //     }
        //    //     Console.WriteLine("index"+AP1.SelectedIndex);
        //    // }
        //    // else if (AP1.SelectedIndex == AP1.Items.IndexOf("12")
        //    //         | (AP1.SelectedIndex == AP1.Items.IndexOf("20"))
        //    //         | (AP1.SelectedIndex == AP1.Items.IndexOf("22"))
        //    //         | (AP1.SelectedIndex == AP1.Items.IndexOf("24"))
        //    //         | (AP1.SelectedIndex == AP1.Items.IndexOf("26"))
        //    //         | (AP1.SelectedIndex == AP1.Items.IndexOf("72"))
        //    //         )
        //    // {
        //    //     if (rdoOtp1.Checked)
        //    //     { numOtpReg.Value = 0xf8; }
        //    //     else if (rdoOtp2.Checked)
        //    //     {
        //    //         numOtpReg.Value = 0xf9;
        //    //     }
        //    //     else if (rdoOtp2.Checked&&((AP1.SelectedIndex == AP1.Items.IndexOf("20"))))
        //    //     {
        //    //         numOtpReg.Value = 0xf9;
        //    //     }


        //}

        private void Label2_Click(object sender, EventArgs e)
        {

        }






        //-- --- ---- ---- ---  -- - ---- code gen start-- --- --- -- --- --- -- - --
        bool flag_gamma = false;
        bool flag_times = false;
        bool flag_Otherpage = false;



        //program enable reg
        //寄存器定义
        byte EE40 = 0;//Gam1-8
        byte ED40 = 0;//Gam9-10
        byte E5D0 = 0;
        byte E4D0 = 0;
        byte F640 = 0;
        byte F740 = 0;
        byte F840 = 0;
        byte F940 = 0;
        byte EC40 = 0;
        byte F040 = 0;
        byte EF40 = 0;




        //清空Gamma那一列
        private void clear_Gamma_Click(object sender, EventArgs e)
        {
            Gamma1.Checked = Gamma2.Checked = Gamma3.Checked = Gamma4.Checked = Gamma5.Checked = Gamma6.Checked
                           = Gamma7.Checked = Gamma8.Checked = Gamma9.Checked = Gamma10.Checked = false;
        }

        //生成代码
        private void Code_GEN_Click(object sender, EventArgs e)
        {

            Flag_all();

            //  ((flag_gamma) && (flag_Otherpage) && (flag_times))  ---- 左边gamma 选了  中间选对了 右边也选了 --错误
            // ((!flag_times) | ((!flag_gamma) && (!flag_Otherpage)))-----中间选对了  两边没有选  --错误
            // (flag_times)|((flag_gamma)|(flag_Otherpage)) 中间选错了，一边选对了  --错误
            // (!flag_times) && ((!flag_gamma) && (!flag_Otherpage))--中间选对了，两边没有选

            if (((flag_gamma) && (flag_Otherpage) && (flag_times)) |
                ((!flag_times) | ((!flag_gamma) && (!flag_Otherpage))) |
                  //(flag_times)|((flag_gamma)|(flag_Otherpage))    |
                  ((!flag_times) && ((!flag_gamma) && (!flag_Otherpage)))

                )


            {
                Display_Box.Text = "选择错误，请重试";

            }

            else
            {


                //引用check状态函数

                selection_result();



                if (Gamma1.Checked | Gamma2.Checked | Gamma3.Checked | Gamma4.Checked | Gamma5.Checked | Gamma6.Checked | Gamma7.Checked | Gamma8.Checked | Gamma9.Checked | Gamma10.Checked)
                {
                    OTP_Head1();
                    REG2Hex();
                    OTP_Tail();
                }
                else
                {
                    OTP_Head2();
                    REG2Hex();
                    OTP_Tail();
                }

            }




            ////如果Gamma那列有一个选中的话，用OTP_Head1()
            //if (Gamma1.Checked | Gamma2.Checked | Gamma3.Checked | Gamma4.Checked | Gamma5.Checked | Gamma6.Checked | Gamma7.Checked | Gamma8.Checked | Gamma9.Checked | Gamma10.Checked)
            //{
            //    OTP_Head1();
            //    REG2Hex();
            //    OTP_Tail();
            //}
            //else
            //{
            //    OTP_Head2();
            //    REG2Hex();
            //    OTP_Tail();
            //}


        }

        //清空显示界面
        private void txt_mian_Click(object sender, EventArgs e)
        {
            Display_Box.Text = "";
        }

        //清空Other那一列
        private void clear_Other_Click(object sender, EventArgs e)
        {
            Page_A0h.Checked = Page_D0h.Checked = Page_D2h.Checked = Page_40h.Checked = Page_60h.Checked = Page_70h.Checked =
            Page_80h.Checked = Page_90h.Checked = Page_E0h.Checked = Page_E2h.Checked = Page_10h.Checked = Page_12h.Checked =
            Page_20h.Checked = Page_22h.Checked = Page_24h.Checked = Page_26h.Checked = Page_72h.Checked = Page_74h.Checked =
            Page_76h.Checked = Page_92h.Checked = Page_14h.Checked = Page_F0h.Checked = Page_F2h.Checked = Page_30h.Checked =
            Page_32h.Checked = Page_34h.Checked = Page_36h.Checked = RCN.Checked = false;
        }


        //所有的flag规定
        private void Flag_all()
        {

            //判断一下 gamma 那列是否选中了一个
            if (Gamma1.Checked | Gamma2.Checked | Gamma3.Checked | Gamma4.Checked | Gamma5.Checked | Gamma6.Checked
                           | Gamma7.Checked | Gamma8.Checked | Gamma9.Checked | Gamma10.Checked)
            {
                flag_gamma = true;
            }
            else
            {
                flag_gamma = false;
            }



            //判断一下 other page 那列是否选中了一个
            if (Page_A0h.Checked | Page_D0h.Checked | Page_D2h.Checked | Page_40h.Checked | Page_60h.Checked | Page_70h.Checked |
            Page_80h.Checked | Page_90h.Checked | Page_E0h.Checked | Page_E2h.Checked | Page_10h.Checked | Page_12h.Checked |
            Page_20h.Checked | Page_22h.Checked | Page_24h.Checked | Page_26h.Checked | Page_72h.Checked | Page_74h.Checked |
            Page_76h.Checked | Page_92h.Checked | Page_14h.Checked | Page_F0h.Checked | Page_F2h.Checked | Page_30h.Checked |
            Page_32h.Checked | Page_34h.Checked | Page_36h.Checked | RCN.Checked)
            {
                flag_Otherpage = true;
            }
            else
            {
                flag_Otherpage = false;
            }


            //判断一下 1 2 3次那列是否只选中了一个，选中了多个报错
            if (((Time_1st

.CheckState == CheckState.Unchecked) | (Time_2nd

.CheckState == CheckState.Unchecked) | (Time_3rd

.CheckState == CheckState.Unchecked)) |
                (Time_1st

.Checked && Time_2nd

.Checked && Time_3rd

.Checked) |
                (Time_1st

.Checked && Time_2nd

.Checked) | (Time_1st

.Checked && Time_3rd

.Checked) | (Time_2nd

.Checked && Time_3rd

.Checked))
            {
                flag_times = true;
                //flag_times = false;
            }
            else
            {
                flag_times = false;
                //flag_times = true;
            }


        }

        private void selection_result()
        {
            if (Time_1st.Checked)
            {
                initialize_reg();

                //gamma 寄存器
                #region
                if (Gamma1.Checked)
                {
                    EE40 |= 1 << 0; //EE40[0]=1
                }
                else
                {
                    EE40 &= 0xFE;//最低置0，其余位不动
                }

                if (Gamma2.Checked)
                {
                    EE40 |= 1 << 1;
                }
                else
                {
                    EE40 &= 0xFD;
                }

                if (Gamma3.Checked)
                {
                    EE40 |= 1 << 2;
                }
                else
                {
                    EE40 &= 0xFB;
                }

                if (Gamma4.Checked)
                {
                    EE40 |= 1 << 3;
                }
                else
                {
                    EE40 &= 0xF7;
                }

                if (Gamma5.Checked)
                {
                    EE40 |= 1 << 4;
                }
                else
                {
                    EE40 &= 0xEF;
                }

                if (Gamma6.Checked)
                {
                    EE40 |= 1 << 5;
                }
                else
                {
                    EE40 &= 0xDF;
                }

                if (Gamma7.Checked)
                {
                    EE40 |= 1 << 6;
                }
                else
                {
                    EE40 &= 0xBF;
                }

                if (Gamma8.Checked)
                {
                    EE40 |= 1 << 7;
                }
                else
                {
                    EE40 &= 0x7F;
                }

                //gamma9 gamma10
                if (Gamma9.Checked)
                {
                    ED40 |= 1 << 0;
                }
                else
                {
                    ED40 &= 0xFE;
                }

                if (Gamma10.Checked)
                {
                    ED40 |= 1 << 1;
                }
                else
                {
                    ED40 &= 0xFD;
                }

                #endregion

                //其他寄存器
                if (Page_A0h.Checked)
                {
                    E5D0 |= 1 << 0;
                }
                else
                {
                    E5D0 &= 0xFE;
                }

                if (Page_D0h.Checked)
                {
                    E5D0 |= 1 << 1;
                }
                else
                {
                    E5D0 &= 0xFD;
                }

                if (Page_D2h.Checked)
                {
                    E5D0 |= 1 << 5;
                }
                else
                {
                    E5D0 &= 0xDF;
                }

                if (Page_40h.Checked)
                {
                    F640 |= 1 << 0;
                }
                else
                {
                    F640 &= 0xFE;
                }

                if (Page_60h.Checked)
                {
                    F640 |= 1 << 1;
                }
                else
                {
                    F640 &= 0xFD;
                }

                if (Page_70h.Checked)
                {
                    F640 |= 1 << 2;
                }
                else
                {
                    F640 &= 0xFB;
                }

                if (Page_80h.Checked)
                {
                    F640 |= 1 << 3;
                }
                else
                {
                    F640 &= 0xF7;
                }

                if (Page_90h.Checked)
                {
                    F640 |= 1 << 4;
                }
                else
                {
                    F640 &= 0xEF;
                }

                if (Page_E0h.Checked)
                {
                    F640 |= 1 << 5;
                }
                else
                {
                    F640 &= 0xDF;
                }

                if (Page_E2h.Checked)
                {
                    F640 |= 1 << 6;
                }
                else
                {
                    F640 &= 0xBF;
                }

                if (Page_10h.Checked)
                {
                    F640 |= 1 << 7;
                }
                else
                {
                    F640 &= 0x7F;
                }

                if (Page_12h.Checked)
                {
                    F840 |= 1 << 0;
                }
                else
                {
                    F840 &= 0xFE;
                }

                if (Page_20h.Checked)
                {
                    F840 |= 1 << 1;
                }
                else
                {
                    F840 &= 0xFD;
                }

                if (Page_22h.Checked)
                {
                    F840 |= 1 << 2;
                }
                else
                {
                    F840 &= 0xFB;
                }

                if (Page_24h.Checked)
                {
                    F840 |= 1 << 3;
                }
                else
                {
                    F840 &= 0xF7;
                }

                if (Page_26h.Checked)
                {
                    F840 |= 1 << 4;
                }
                else
                {
                    F840 &= 0xEF;
                }

                if (Page_72h.Checked)
                {
                    F840 |= 1 << 5;
                }
                else
                {
                    F840 &= 0xDF;
                }

                if (Page_74h.Checked)
                {
                    EC40 |= 1 << 3;
                }
                else
                {
                    EC40 &= 0xF7;
                }

                if (Page_76h.Checked)
                {
                    EC40 |= 1 << 5;
                }
                else
                {
                    EC40 &= 0xDF;
                }

                if (Page_92h.Checked)
                {
                    F040 |= 1 << 4;
                }
                else
                {
                    F040 &= 0xEF;
                }

                if (Page_14h.Checked)
                {
                    F040 |= 1 << 6;
                }
                else
                {
                    F040 &= 0xBF;
                }

                if (Page_F0h.Checked)
                {
                    F040 |= 1 << 0;
                }
                else
                {
                    F040 &= 0xFE;
                }

                if (Page_F2h.Checked)
                {
                    F040 |= 1 << 2;
                }
                else
                {
                    F040 &= 0xFB;
                }

                if (Page_30h.Checked)
                {
                    EF40 |= 1 << 0;
                }
                else
                {
                    EF40 &= 0xFE;
                }

                if (Page_32h.Checked)
                {
                    EF40 |= 1 << 1;
                }
                else
                {
                    EF40 &= 0xFD;
                }

                if (Page_34h.Checked)
                {
                    EF40 |= 1 << 2;
                }
                else
                {
                    EF40 &= 0xFB;
                }

                if (Page_36h.Checked)
                {
                    EF40 |= 1 << 3;
                }
                else
                {
                    EF40 &= 0xF7;
                }

                if (RCN.Checked)
                {
                    F840 |= 1 << 6;
                }
                else
                {
                    F840 &= 0xBF;
                }

            }

            if (Time_2nd.Checked)
            {
                initialize_reg();

                #region
                if (Gamma1.Checked)
                {
                    EE40 |= 1 << 0; //EE40[0]=1
                }
                else
                {
                    EE40 &= 0xFE;//最低置0，其余位不动
                }

                if (Gamma2.Checked)
                {
                    EE40 |= 1 << 1;
                }
                else
                {
                    EE40 &= 0xFD;
                }

                if (Gamma3.Checked)
                {
                    EE40 |= 1 << 2;
                }
                else
                {
                    EE40 &= 0xFB;
                }

                if (Gamma4.Checked)
                {
                    EE40 |= 1 << 3;
                }
                else
                {
                    EE40 &= 0xF7;
                }

                if (Gamma5.Checked)
                {
                    EE40 |= 1 << 4;
                }
                else
                {
                    EE40 &= 0xEF;
                }

                if (Gamma6.Checked)
                {
                    EE40 |= 1 << 5;
                }
                else
                {
                    EE40 &= 0xDF;
                }

                if (Gamma7.Checked)
                {
                    EE40 |= 1 << 6;
                }
                else
                {
                    EE40 &= 0xBF;
                }

                if (Gamma8.Checked)
                {
                    EE40 |= 1 << 7;
                }
                else
                {
                    EE40 &= 0x7F;
                }

                //gamma9 gamma10
                if (Gamma9.Checked)
                {
                    ED40 |= 1 << 0;
                }
                else
                {
                    ED40 &= 0xFE;
                }

                if (Gamma10.Checked)
                {
                    ED40 |= 1 << 1;
                }
                else
                {
                    ED40 &= 0xFD;
                }
                #endregion

                //其他寄存器
                #region
                if (Page_D0h.Checked)
                {
                    E4D0 |= 1 << 1; ;
                }
                else
                {
                    E4D0 &= 0xFD;
                }

                if (Page_D2h.Checked)
                {
                    E4D0 |= 1 << 5;
                }
                else
                {
                    E4D0 &= 0xDF;
                }

                if (Page_40h.Checked)
                {
                    F740 |= 1 << 0;
                }
                else
                {
                    F740 &= 0xFE;
                }

                if (Page_60h.Checked)
                {
                    F740 |= 1 << 1;
                }
                else
                {
                    F740 &= 0xFD;
                }

                if (Page_70h.Checked)
                {
                    F740 |= 1 << 2;
                }
                else
                {
                    F740 &= 0xFB;
                }

                if (Page_80h.Checked)
                {
                    F740 |= 1 << 3;
                }
                else
                {
                    F740 &= 0xF7;
                }

                if (Page_90h.Checked)
                {
                    F740 |= 1 << 4;
                }
                else
                {
                    F740 &= 0xEF;
                }

                if (Page_E0h.Checked)
                {
                    F740 |= 1 << 5;
                }
                else
                {
                    F740 &= 0xDF;
                }

                if (Page_E2h.Checked)
                {
                    F740 |= 1 << 6;
                }
                else
                {
                    F740 &= 0xBF;
                }

                if (Page_10h.Checked)
                {
                    F740 |= 1 << 7;
                }
                else
                {
                    F740 &= 0x7F;
                }

                if (Page_12h.Checked)
                {
                    F940 |= 1 << 0;
                }
                else
                {
                    F940 &= 0xFE;
                }

                if (Page_20h.Checked)
                {
                    F940 |= 1 << 1;
                }
                else
                {
                    F940 &= 0xFD;
                }

                if (Page_22h.Checked)
                {
                    F940 |= 1 << 2;
                }
                else
                {
                    F940 &= 0xFB;
                }

                if (Page_24h.Checked)
                {
                    F940 |= 1 << 3;
                }
                else
                {
                    F940 &= 0xF7;
                }

                if (Page_26h.Checked)
                {
                    F940 |= 1 << 4;
                }
                else
                {
                    F940 &= 0xEF;
                }

                if (Page_72h.Checked)
                {
                    F940 |= 1 << 5;
                }
                else
                {
                    F940 &= 0xDF;
                }

                if (Page_74h.Checked)
                {
                    EC40 |= 1 << 4;
                }
                else
                {
                    EC40 &= 0xEF;
                }

                if (Page_76h.Checked)
                {
                    EC40 |= 1 << 6;
                }
                else
                {
                    EC40 &= 0xBF;
                }

                if (Page_92h.Checked)
                {
                    F040 |= 1 << 5;
                }
                else
                {
                    F040 &= 0xDF;
                }

                if (Page_14h.Checked)
                {
                    F040 |= 1 << 7;
                }
                else
                {
                    F040 &= 0x7F;
                }

                if (Page_F0h.Checked)
                {
                    F040 |= 1 << 1;
                }
                else
                {
                    F040 &= 0xFD;
                }

                if (Page_F2h.Checked)
                {
                    F040 |= 1 << 3;
                }
                else
                {
                    F040 &= 0xFB;
                }

                if (Page_30h.Checked)
                {
                    EF40 |= 1 << 4;
                }
                else
                {
                    EF40 &= 0xEF;
                }

                if (Page_32h.Checked)
                {
                    EF40 |= 1 << 5;
                }
                else
                {
                    EF40 &= 0xDF;
                }

                if (Page_34h.Checked)
                {
                    EF40 |= 1 << 6;
                }
                else
                {
                    EF40 &= 0xBF;
                }

                if (Page_36h.Checked)
                {
                    EF40 |= 1 << 7;
                }
                else
                {
                    EF40 &= 0x7F;
                }

                if (RCN.Checked)
                {
                    F840 |= 1 << 7;
                }
                else
                {
                    F840 &= 0x7F;
                }

                #endregion
            }

            if (Time_3rd.Checked)
            {

                initialize_reg();
                #region
                if (Gamma1.Checked)
                {
                    EE40 |= 1 << 0; //EE40[0]=1
                }
                else
                {
                    EE40 &= 0xFE;//最低置0，其余位不动
                }



                if (Gamma2.Checked)
                {
                    EE40 |= 1 << 1;
                }
                else
                {
                    EE40 &= 0xFD;
                }

                if (Gamma3.Checked)
                {
                    EE40 |= 1 << 2;
                }
                else
                {
                    EE40 &= 0xFB;
                }


                if (Gamma4.Checked)
                {
                    EE40 |= 1 << 3;
                }
                else
                {
                    EE40 &= 0xF7;
                }


                if (Gamma5.Checked)
                {
                    EE40 |= 1 << 4;
                }
                else
                {
                    EE40 &= 0xEF;
                }



                if (Gamma6.Checked)
                {
                    EE40 |= 1 << 5;
                }
                else
                {
                    EE40 &= 0xDF;
                }


                if (Gamma7.Checked)
                {
                    EE40 |= 1 << 6;
                }
                else
                {
                    EE40 &= 0xBF;
                }


                if (Gamma8.Checked)
                {
                    EE40 |= 1 << 7;
                }
                else
                {
                    EE40 &= 0x7F;
                }



                //gamma9 gamma10
                if (Gamma9.Checked)
                {
                    ED40 |= 1 << 0;
                }
                else
                {
                    ED40 &= 0xFE;
                }


                if (Gamma10.Checked)
                {
                    ED40 |= 1 << 1;
                }
                else
                {
                    ED40 &= 0xFD;
                }

                #endregion

                //其他寄存器
                if (Page_20h.Checked)
                {
                    F940 |= 1 << 7;
                }
                else
                {
                    F940 &= 0x7F;
                }
            }
        }

        //gamma的OTP代码的固定头部
        private void OTP_Head1()  //产生gamma的代码的头部
        {

            Display_Box.Text += "//------新的开始--------" + "\r\n";
            Display_Box.Text += "FE,00" + "\r\n" + "28" + "\r\n" + "10" + "\r\n" + "FE,42" + "\r\n" + "03,10" + "\r\n" + "04,32"
                + "\r\n" + "05,10" + "\r\n" + "06,32" + "\r\n" + "07,10" + "\r\n"
                + "08,32" + "\r\n" + "09,10" + "\r\n" + "0A,32" + "\r\n" + "0B,10" + "\r\n" + "0C,32" + "\r\n"; //烧录头代码
        }
        private void OTP_Head2()
        {
            Display_Box.Text += "//------新的开始--------" + "\r\n";
            Display_Box.Text += "FE,00" + "\r\n" + "28" + "\r\n" + "10" + "\r\n"; //烧录头代码 
        }

        //otp尾部代码
        private void OTP_Tail()
        {
            Display_Box.Text += "FE,40" + "\r\n" + "F2,01" + "\r\n" + "F3,A5" + "\r\n" + "F4,5A" + "\r\n" + "F5,3C" + "\r\n";// 烧录尾代码
        }


        //将寄存器的值表示成16进制，并写成标准形式
        private void REG2Hex()
        {

            if (EE40 == 0)
            {
                Display_Box.Text += "";
            }
            else
            {
                Display_Box.Text += "FE,40" + "\r\n" + "EE," + EE40.ToString("X2") + "\r\n";
            }

            if (ED40 == 0)
            {
                Display_Box.Text += "";
            }
            else
            {
                Display_Box.Text += "FE,40" + "\r\n" + "ED," + ED40.ToString("X2") + "\r\n";
            }

            if (E5D0 == 0)
            {
                Display_Box.Text += "";
            }
            else
            {
                Display_Box.Text += "FE,D0" + "\r\n" + "E5," + E5D0.ToString("X2") + "\r\n";
            }

            if (E4D0 == 0)
            {
                Display_Box.Text += "";
            }
            else
            {
                Display_Box.Text += "FE,D0" + "\r\n" + "E4," + E4D0.ToString("X2") + "\r\n";
            }

            if (F640 == 0)
            {
                Display_Box.Text += "";
            }
            else
            {
                Display_Box.Text += "FE,40" + "\r\n" + "F6," + F640.ToString("X2") + "\r\n";
            }

            if (F740 == 0)
            {
                Display_Box.Text += "";
            }
            else
            {
                Display_Box.Text += "FE,40" + "\r\n" + "F7," + F740.ToString("X2") + "\r\n";
            }

            if (F840 == 0)
            {
                Display_Box.Text += "";
            }
            else
            {
                Display_Box.Text += "FE,40" + "\r\n" + "F8," + F840.ToString("X2") + "\r\n";
            }

            if (F940 == 0)
            {
                Display_Box.Text += "";
            }
            else
            {
                Display_Box.Text += "FE,40" + "\r\n" + "F9," + F940.ToString("X2") + "\r\n";
            }

            if (EC40 == 0)
            {
                Display_Box.Text += "";
            }
            else
            {
                Display_Box.Text += "FE,40" + "\r\n" + "EC," + EC40.ToString("X2") + "\r\n";
            }

            if (F040 == 0)
            {
                Display_Box.Text += "";
            }
            else
            {
                Display_Box.Text += "FE,40" + "\r\n" + "F0," + F040.ToString("X2") + "\r\n";

            }


            if (EF40 == 0)
            {
                Display_Box.Text += "";
            }
            else
            {
                Display_Box.Text += "FE,40" + "\r\n" + "EF," + EF40.ToString("X2") + "\r\n";
            }


            //Display_Box.Text += "FE,40" + "\r\n" + "EE," + EE40.ToString("X2") + "\r\n";
            //Display_Box.Text += "FE,40" + "\r\n" + "ED," + ED40.ToString("X2") + "\r\n";
            //Display_Box.Text += "FE,D0" + "\r\n" + "E5," + E5D0.ToString("X2") + "\r\n";
            //Display_Box.Text += "FE,D0" + "\r\n" + "E4," + E4D0.ToString("X2") + "\r\n";
            //Display_Box.Text += "FE,40" + "\r\n" + "F6," + F640.ToString("X2") + "\r\n";
            //Display_Box.Text += "FE,40" + "\r\n" + "F7," + F740.ToString("X2") + "\r\n";
            //Display_Box.Text += "FE,40" + "\r\n" + "F8," + F840.ToString("X2") + "\r\n";
            //Display_Box.Text += "FE,40" + "\r\n" + "F9," + F940.ToString("X2") + "\r\n";
            //Display_Box.Text += "FE,40" + "\r\n" + "EC," + EC40.ToString("X2") + "\r\n";
            //Display_Box.Text += "FE,40" + "\r\n" + "F0," + F040.ToString("X2") + "\r\n";
            //Display_Box.Text += "FE,40" + "\r\n" + "EF," + EF40.ToString("X2") + "\r\n";

        }

        //初始化一次，清空上次残留值
        private void initialize_reg()
        {
            byte EE40 = 0;
            byte ED40 = 0;
            byte E5D0 = 0;
            byte E4D0 = 0;
            byte F640 = 0;
            byte F740 = 0;
            byte F840 = 0;
            byte F940 = 0;
            byte EC40 = 0;
            byte F040 = 0;
            byte EF40 = 0;
        }







        //-- --- ---- ---- ---  -- - ---- code gen stop-- --- --- -- --- --- -- - --










    }
}
